/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved. 
 */
package com.icinfo.cloud.provider.punish.ucase.casemain.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.approval.dto.MemberUserVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.DistributionDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.EditDistributionDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseDistributionRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.DistributionVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述:  case_distribution_record 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年11月15日
 */
@RestController
@RefreshScope
@RequestMapping("/punish/ucase/case/distribution")
@Slf4j
public class CaseDistributionRecordController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseDistributionRecordController.class);

    @Resource
    private ICaseDistributionRecordService caseDistributionRecordService;

    /**
     * 描述: 分配法制人员-分配列表
     * @author zhanghongqiang
     * @Date 2022/11/15
     * @param distributionDto
     * @return com.icinfo.framework.common.web.Result
     */
    @PostMapping("/readDistributionList")
    @ApiOperation(value = "【V1.8.0】分配法制人员-分配列表", httpMethod = "POST")
    public Result<PageResponse<DistributionVo>> readDistributionList(@RequestBody @Validated DistributionDto distributionDto) {
        List<DistributionVo> distributionVos =  caseDistributionRecordService.getDistributionList(distributionDto);
        return Result.success(Constant.STRING_GET_SUCCESS, new PageResponse<>(distributionVos));
    }

    /**
     * 描述: 分配法制人员-分配操作提交
     * @author zhanghongqiang
     * @Date 2022/11/15
     * @param editDistributionDto
     * @return com.icinfo.framework.common.web.Result
     */
    @PostMapping("/editDistribution")
    @ApiOperation(value = "【V1.8.0】分配法制人员-分配操作提交", httpMethod = "POST")
    public Result<String> editDistribution(@RequestBody @Validated EditDistributionDto editDistributionDto) {
        caseDistributionRecordService.editDistribution(editDistributionDto);
        return Result.success(Constant.STRING_SAVE_SUCCESS);
    }

    /**
     * 描述: 分配法制人员-分配弹窗(查询案件所属机构的法制人员)
     * @author zhanghongqiang
     * @Date 2022/11/15
     * @param caseOrgCode 案件的orgCode
     * @return com.icinfo.framework.common.web.Result
     */
    @GetMapping("/readDistributionPeople")
    @ApiOperation(value = "【V1.8.0】分配法制人员-分配弹窗")
    public Result<List<MemberUserVo>> readDistributionPeople(@RequestParam(value = "caseOrgCode",required = false) String caseOrgCode) {
        List<MemberUserVo> memberUserVos = caseDistributionRecordService.getDistributionPeople(caseOrgCode);
        return Result.success(Constant.STRING_GET_SUCCESS,memberUserVos);
    }
}